package com.shenmazong.servereduschool.service.impl;

import com.shenmazong.servereduschool.entity.TbMajor;
import com.shenmazong.servereduschool.mapper.TbMajorMapper;
import com.shenmazong.servereduschool.service.ITbMajorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 专业表——suliven 服务实现类
 * </p>
 *
 * @author 关好帅
 * @since 2021-09-22
 */
@Service
public class TbMajorServiceImpl extends ServiceImpl<TbMajorMapper, TbMajor> implements ITbMajorService {

    @Autowired
    private TbMajorMapper majorMapper;

    @Override
    public ResultResponse createMajor(TbMajor major) {
        try {
            majorMapper.insert(major);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteMajor(BatchChooseIdVo idVo) {
        if(idVo.getIds().size()<=0){
            return ResultResponse.FAILED("请至少选择一个删除！");
        }
        try {
            majorMapper.deleteBatchIds(idVo.getIds());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateMajor(TbMajor major) {
        try {
            majorMapper.updateById(major);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }
}
